//
//  oldMyCenterViewController.m
//  laonianbang
//
//  Created by 勇拓 李 on 17/10/15.
//  Copyright © 2017年 zaiyou. All rights reserved.
//

#import "oldMyCenterViewController.h"
#import "oldMyCenterCell.h"
#import "oldMyCenterHeaderView.h"
#import "oldHistoryOrdersViewController.h"
#import "oldPersonalInfoViewController.h"
#import "oldHistoryOrderListViewController.h"
#import "oldMyBalanceViewController.h"
#import "oldLoginViewController.h"
#import "AppDelegate.h"
#import "oldFamilyParentListTableViewController.h"
#import "oldSettingsViewController.h"

@interface oldMyCenterViewController ()<oldServerStatusWarningDelegate>
@property (nonatomic, strong)oldMyCenterHeaderView *headerView;
@end

static NSString *const identifier = @"oldMyCenterCell";

@implementation oldMyCenterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
//    self.navigationController.navigationBar.translucent = YES;
//    self.navigationController.navigationBarHidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
//    self.navigationController.navigationBar.translucent = NO;
//    self.navigationController.navigationBarHidden = NO;
}

#pragma mark - initView
- (void)initView
{
    [self rigisterCell:identifier];
    self.tableView.backgroundColor = Color_With_Rgb(247, 247, 247, 1);
    [self initHeader];
}

- (void)initHeader
{
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 225)];
    
    self.headerView.frame = headerView.bounds;
    
    self.tableView.tableHeaderView = headerView;
    
    [headerView addSubview:self.headerView];
}

- (oldMyCenterHeaderView *)headerView
{
    if (!_headerView) {
        oldMyCenterHeaderView *view = [[[NSBundle mainBundle] loadNibNamed:@"oldMyCenterHeaderView"
                                                                     owner:self
                                                                   options:nil] objectAtIndex:0];
        _headerView = view;
        _headerView.vc = self;
        _headerView.delegate = self;
    }
    
    return _headerView;
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    switch (section) {
        case 0:
            return 4;
            break;
        default:
            return 0;
            break;
    }
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    switch (indexPath.section) {
        case 0:
            return [self configFristSection:tableView indexPath:indexPath];
            break;
        default:
            return nil;
            break;
    }
}


- (UITableViewCell *)configFristSection:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath
{
    oldMyCenterCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];
    
    if (cell == nil) {
        cell = [[oldMyCenterCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    
    switch (indexPath.row) {
        case 0:
            [cell.btn_img setImage:[UIImage imageNamed:@"我的亲属"] forState:UIControlStateNormal];
            cell.label_title.text = @"我的亲属";
            break;
        case 1:
            [cell.btn_img setImage:[UIImage imageNamed:@"我的余额"] forState:UIControlStateNormal];
            cell.label_title.text = @"我的余额";
            break;
        case 2:
            [cell.btn_img setImage:[UIImage imageNamed:@"个人资料"] forState:UIControlStateNormal];
            cell.label_title.text = @"个人资料";
            break;;
        case 3:
            [cell.btn_img setImage:[UIImage imageNamed:@"设置"] forState:UIControlStateNormal];
            cell.label_title.text = @"设置";
            break;
//        case 4:
//            [cell.btn_img setImage:[UIImage imageNamed:@"关于"] forState:UIControlStateNormal];
//            cell.label_title.text = @"退出";
            break;
        default:
            break;
    }
    
    return cell;
    
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 50;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    switch (indexPath.row) {
        case 0:
        {
            oldFamilyParentListTableViewController *vc = [oldFamilyParentListTableViewController new];
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 1:
        {
            oldMyBalanceViewController *vc = [oldMyBalanceViewController new];
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 2:
        {
            oldPersonalInfoViewController *vc = [oldPersonalInfoViewController new];
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 3:
        {
            oldSettingsViewController *vc = [oldSettingsViewController new];
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        default:
            break;
    }
}

#pragma mark - scrollView
- (void)scrollViewDidScroll:(UIScrollView *)sender{
    if (sender.contentOffset.y < 0) {
        [sender setContentOffset:CGPointMake(sender.contentOffset.x, 0)];
    }
}

#pragma headerDelegate
- (void)statusWarning:(NSString *)warning needGotoCerVc:(BOOL)need
{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:warning preferredStyle:UIAlertControllerStyleAlert];
    
    if (need) {
        UIAlertAction *chooseReason = [UIAlertAction actionWithTitle:@"查看证书" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            [self gotoCerVc];
        }];
        
        UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil];
        
        [alert addAction:chooseReason];
        [alert addAction:cancel];
    }
    else
    {
        UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"好的" style:UIAlertActionStyleDefault handler:nil];
        [alert addAction:cancel];
    }
    
    [self presentViewController:alert animated:YES completion:nil];
}

- (void)gotoCerVc
{
    
}

@end
